package com.liang.socketupdown;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class ServerSocketDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10000);

        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,//核心线程
                10,//最多线程数
                60,//保存时间
                TimeUnit.SECONDS,//保存时间单位
                new ArrayBlockingQueue<>(3),//阻塞队列
                Executors.defaultThreadFactory(),//默认工厂
                new ThreadPoolExecutor.AbortPolicy()//拒绝策略
        );

        while (true) {
            Socket accept = ss.accept();
            CopyThread ct = new CopyThread(accept);

            pool.submit(ct);
        }

    }
}
